home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / bs941029.tgz / bbsx-941029.tar / bbsx / genpasswd.c < prev    next >
C/C++ Source or Header  |  1994-10-29  |  1KB  |  69 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <ctype.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. #include <fcntl.h>
  8.  
  9. int get_passwd(char *filename, char *timestamp, char *password)
  10. {
  11.   int  fd;
  12.   int offset;
  13.   int min, hour, day;
  14.   char buf[1024];
  15.   int i;
  16.  
  17.   if ((fd=open(filename,O_RDONLY)) == -1) {
  18.      perror("file not found");
  19.      exit(0);
  20.   }   
  21.  
  22.   if (strlen(timestamp) != 10) {
  23.      perror("format error in timestring");
  24.      exit(0);
  25.   }   
  26.  
  27.   strncpy(buf, timestamp, 2); buf[2] = '\0';
  28.   day = atoi(buf);
  29.   strncpy(buf, ×tamp[6], 2); buf[2] = '\0';
  30.   hour = atoi(buf);
  31.   strncpy(buf, ×tamp[8], 2); buf[2] = '\0';
  32.   min = atoi(buf);
  33.  
  34.   offset = ((min + day) % 60) * 27 + hour;
  35.  
  36.   if (hour > 23) exit(0);
  37.  
  38.   if(lseek(fd, (long) (offset), SEEK_SET) == -1) exit(0);
  39.   
  40.   if(read(fd, password, 4) < 1) exit(0);
  41.   
  42.   password[4] = '\0';
  43.   
  44.   close(fd);
  45.  
  46.   return 1;
  47. }
  48.  
  49.  
  50. main(int argc, char **argv)
  51. {
  52.   FILE *fp;
  53.   char filename[1024];
  54.   char timestring[1024];
  55.   char password[1024];
  56.   
  57.   if (argc > 1) {
  58.     sprintf(filename,"/users/bbs/%s.pwd",argv[1]);
  59.   } else  {
  60.     printf("Enter passwordfile-name: ");
  61.     gets(filename);
  62.   }  
  63.   printf("Enter Timestring: ");
  64.   gets(timestring);
  65.   get_passwd(filename, timestring, password);
  66.   printf("Password is: %s\n", password);
  67.   
  68.   return 0;
  69. }